package com.renjian.spring.day04.aopanno;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

//增强的类
@Component
@Aspect //生成代理对象
@Order(3)
public class UserProxy {

    //相同切入点抽取
    @Pointcut("execution(* com.renjian.spring.day04.aopanno.User.add(..))")
    public void samePoint(){

    }

   //  前置通知
    @Before(value = "samePoint()")
   //@Before注解表示作为前置通知
    public void before(){
        System.out.println("before........");
    }

    //最终通知
    @After(value = "samePoint()")
    public void after(){
        System.out.println("after......");
    }

    //返回通知(后置通知)
    @AfterReturning(value = "samePoint()")
    public void afterReturning(){
        System.out.println("AfterReturning......");
    }

    //异常通知
    @AfterThrowing(value = "samePoint()")
    public void afterThrowing(){
        System.out.println("AfterThrowing......");
    }

    //环绕通知
    @Around(value = "samePoint()")
    public void arund(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕之前......");

        //被增强的方法执行
        proceedingJoinPoint.proceed();

        System.out.println("环绕之后......");
    }
}
